/**
 * 
 */
app.factory('candCandidateService', ['$http', '$q', function($http, $q) {
	var baseUrl = '/DRMS/api';
	return function() {
		var promise = $q(function(resolve, reject) {
			$http({
				url: baseUrl + '/drmscandidate/selectAllCandidates',
				method: 'POST',
			}).then(function(response) {
				resolve(response.data);	
				console.log(response.data);
			}, function(response) {
				reject('candCandidateService - reject');
			});
		}); 		
		return promise;
	}
}]);

app.factory('getCandidateService',['$http','$q',function($http,$q){
	var baseUrl = '/DRMS/api';
	return function(candShowId){
		var promise = $q(function(resolve,reject){
			$http({
				url: baseUrl + '/drmscandidate/getCandidates',
				method:'POST',
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				},
				data: 'candShowId='+candShowId
			}).then(function(response) {
				resolve(response.data);	
				console.log(response.data);
			}, function(response) {
				reject('candCandidateService - reject');
			});
		});
		return promise;
	}
}]);

app.factory('candUpdateService',['$http','$q', function($http,$q) {
	var baseUrl = '/DRMS/api';
	var candUpdateService = {
			
			candidate: function(cand) {
				var promise = $q(function(resolve,reject){
					$http({
						url:baseUrl+'/drmscandidate/updateCandidates',
						method: 'POST',
						headers: {
							'Content-Type': 'application/json'
						},
						data: cand
					}).then(function successCallback(response) {
						resolve (response);
						return response.data;
					}, function errorCallback(response) {
						console.log(response);
					});
				});
				return promise;
			},
	};
	return candUpdateService;
}]);


app.factory('canCallbackService', ['$q', function($q) {
	var defered = $q.defer();
	return {
		promiseDeferd: defered,
		getPromise: defered.promise
	}
}]);

app.factory('candidateService', ['$http', function($http) {
	var baseUrl = '/DRMS/api';	
	var candidateService = {
		candidates: function(cands) {
		    var promise = $http({
		    	url:baseUrl+'/drmscandidate/insertCandidate',
		    	method: 'POST',
		    	headers: {
		    		'Content-Type': 'application/json'
		    	},
		    	data: cands
		    }).then(function successCallback(response) {
		    	console.log(response);
		    	return response.data;
		    }, function errorCallback(response) {
		    	console.log(response);
		    });
		    return promise;
		},
 };
	return candidateService;
}]);

app.factory('toInterviewService',['$http',function($http){
	var baseUrl = '/DRMS/api';
	var toInterviewService = {
			candToInterview:function(candId){
				var promise=$http({
			    	url:baseUrl+'/interview/candToInterview',
			    	method: 'POST',
			    	headers: {
			    		'Content-Type': 'application/x-www-form-urlencoded'
			    	},
			    	data: 'candId='+candId
			    }).then(function successCallback(response) {
			    	console.log(response.data);
					return response.data;
				}, function errorCallback(response) {
					console.log(response.data);
					return response;
				});
					return promise;	
				},
			};
	return toInterviewService;
}]);
